package com.smart.modules.genealogy.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.modules.genealogy.domain.CommonTable;
import com.smart.modules.genealogy.service.ICommonTableService;
import com.smart.system.common.result.Result;
import com.smart.system.common.result.PageResult;

import java.util.List;


/**
 * 公共数据Controller
 */
@RestController
@RequestMapping("/genealogy/table")
public class CommonTableController
{
    @Autowired
    private ICommonTableService commonTableService;

    @GetMapping("/GXList")
    public Result GXList()
    {
        List<CommonTable> page = commonTableService.selectCommonTableGXList();
        return Result.success(page);
    }
    @GetMapping("/eventList")
    public Result eventList()
    {
        List<CommonTable> page = commonTableService.selectCommonTableEventList();
        return Result.success(page);
    }


    /**
     * 查询公共数据列表
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:table:list')")
    @GetMapping("/list")
    public PageResult list(CommonTable commonTable)
    {

        IPage<CommonTable> pageModel = new Page<CommonTable>(commonTable.getPageNum(),commonTable.getPageSize());
        IPage<CommonTable> page = commonTableService.selectCommonTableList(pageModel,commonTable);
        return PageResult.success(page);
    }


    /**
     * 获取公共数据详细信息
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:table:query')")
    @GetMapping(value = "/{groupId}")
    public Result getInfo(@PathVariable("groupId") Long groupId)
    {
        return Result.success(commonTableService.selectCommonTableByGroupId(groupId));
    }

    /**
     * 新增公共数据
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:table:add')")
    @PostMapping
    public Result add(@RequestBody CommonTable commonTable)
    {
        return Result.success(commonTableService.insertCommonTable(commonTable));
    }

    /**
     * 修改公共数据
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:table:edit')")
    @PutMapping
    public Result edit(@RequestBody CommonTable commonTable)
    {
        return Result.success(commonTableService.updateCommonTable(commonTable));
    }

    /**
     * 删除公共数据
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:table:remove')")
    @DeleteMapping("/{groupIds}")
    public Result remove(@PathVariable Long[] groupIds)
    {
        return Result.success(commonTableService.deleteCommonTableByGroupIds(groupIds));
    }
}
